﻿using System.Collections.Generic;
using DC2010.Objects.Base;
using DC2010.Objects.Common;
using DC2010.Objects.Data;
using DC2010.Objects.Logic;

namespace DC2010.Conditions
{
    public class ConditionLogic : BaseLogic
    {
        public ConditionLogic(ConditionData cd)
        {
            Info = new ConditionInfo();
            Gfx = Root.I.ConditionSystem.GetGfx(cd.GfxId);
            Data = cd;
        }

        public ConditionInfo Info { get; set; }
        public ConditionGfx Gfx { get; set; }


        public virtual bool CheckCondition(BaseObject aInvoker, BaseObject aTarget) {
            return true;}

        public void HandleEffects(bool ConditionResult, BaseObject aInvoker, BaseObject aTarget)
        {
            List<KeyValue> sef = new List<KeyValue>();
            if (ConditionResult)
                sef = ((ConditionData)Data).TrueEffect;
            else
                sef = ((ConditionData)Data).FalseEffect;

            //process effects.
            foreach (KeyValue seff in sef)
            {
                EffectData ef = Root.I.EffectSystem.GetData(seff.Value);
                    
                ef.IsActive = ConditionResult;
                ef.L.Pump(aTarget);
            }
        }
    }
}
